package com.hangzhou.welbeing.welbeinginstrument.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.bean.ForYourCustomDateBean;
import com.hangzhou.welbeing.welbeinginstrument.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * 时间 2017 年 09 月 26.
 * 作者 Administrator  刘传华
 * 公司 杭州惟君医疗科技有限公司
 * 包名 com.hangzhou.welbeing.pregnant.welbeing_pregnant.adapter
 * 工程名 welbeing_pregnant
 */
public class ForYourCustomAdapter extends  RecyclerView.Adapter<ForYourCustomAdapter.ViewHolder> implements View.OnClickListener{
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<ForYourCustomDateBean.DataBean> mlist = new ArrayList<>();
    private Context mcontent;
    public ForYourCustomAdapter(List<ForYourCustomDateBean.DataBean> bean, Context content) {
        mlist.addAll(bean);
        mcontent = content;
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_for_your_custom_recyclerview,parent,false);
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tv_content.setText(mlist.get(position).intro);
        holder.tv_desc.setText(mlist.get(position).art_name);
        Glide.with(mcontent).load(mlist.get(position).art_url).into(holder.iv_picture);

    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    @Override
    public void onClick(View v) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(v);
        }
    }
    /**
     * 身体布局Holder
     */
    static class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_desc;
        private  TextView tv_content;



        private ImageView iv_picture;

        public ViewHolder(View itemView) {
            super(itemView);
            tv_desc =  (TextView) itemView.findViewById(R.id.item_for_your_custom_recyclerview_tv_desc);
            tv_content =  (TextView) itemView.findViewById(R.id.item_for_your_custom_recyclerview_tv_content);

            iv_picture =  (ImageView) itemView.findViewById(R.id.item_for_your_custom_recyclerview_iv_picture);

        }
    }
}
